package br.com.mtech.ctrlliberty.clientjar.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="tbUsuario")
@SequenceGenerator(name="sqUsuario", sequenceName="sqUsuario", allocationSize=10)
public class UsuarioVO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 289159594410509313L;
	
	@Id
	@Column(name="idUsuario")
	@GeneratedValue(generator="sqUsuario", strategy=GenerationType.SEQUENCE)
	private Long id;
	
	@Column(name="login", unique=true, nullable=false)
	private String login;

	@Column(name="password", nullable=false)
	private String senha;
	
	@Column(name="nome", nullable=false)
	private String nome;
	
	@OneToMany(mappedBy="usuario", cascade={CascadeType.ALL})
	private List<TelefoneVO> listaTelefone = new ArrayList<TelefoneVO>();

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getSenha() {
		return senha;
	}

	public void setSenha(String senha) {
		this.senha = senha;
	}

	public String getNome() {
		return nome;
	}

	public void setNome(String nome) {
		this.nome = nome;
	}

	public List<TelefoneVO> getListaTelefone() {
		return listaTelefone;
	}

	public void setListaTelefone(List<TelefoneVO> listaTelefone) {
		this.listaTelefone = listaTelefone;
	}
	
	public void addTelefone(TelefoneVO telefone) {
		telefone.setUsuario(this);
		this.getListaTelefone().add(telefone);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((login == null) ? 0 : login.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UsuarioVO other = (UsuarioVO) obj;
		if (login == null) {
			if (other.login != null)
				return false;
		} else if (!login.equals(other.login))
			return false;
		return true;
	}
	
}
